package cn.xy.ymcc.service.impl;

import cn.xy.ymcc.domain.MessageBlacklist;
import cn.xy.ymcc.domain.MessageSms;
import cn.xy.ymcc.mapper.MessageBlacklistMapper;
import cn.xy.ymcc.service.IMessageBlacklistService;
import cn.xy.ymcc.service.IMessageSmsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xy.cao
 * @since 2022-07-19
 */
@Service
public class MessageBlacklistServiceImpl extends ServiceImpl<MessageBlacklistMapper, MessageBlacklist> implements IMessageBlacklistService {

    @Autowired
    private MessageBlacklistMapper messageBlacklistMapper;

    @Autowired
    private IMessageSmsService messageSmsService;

    /**
     * 移除黑名单
     * @param messageBlacklist
     */
    @Override
    public void removeBlock(MessageBlacklist messageBlacklist) {
        MessageSms messageSms = new MessageSms();
        //拷贝数据
        BeanUtils.copyProperties(messageBlacklist,messageSms);
        //置空id
        messageBlacklist.setId(null);
        //添加
        messageSmsService.insert(messageSms);
        //根据id删除
        messageBlacklistMapper.deleteById(messageBlacklist.getId());

    }

    /**
     * 根据号码查询
     * @param phone
     * @return
     */
    @Override
    public MessageBlacklist selectByPhone(String phone) {
        return messageBlacklistMapper.selectByPhone(phone);
    }
}
